import {
  Post,
  Get,
  Put,
  Query,
  Body,
  Controller,
  Provide,
  Inject,
  ALL,
} from '@midwayjs/decorator';
import { CreateRole, UpdateRoleDto } from '../../../dto/admin/sys/userRole';
import { SysRoleServiec } from '../../../service/admin/sys/role';
import { BaseContrall } from '../../base';

@Provide()
@Controller('/admin')
export class SysRoleController extends BaseContrall {
  @Inject()
  sysRoleService: SysRoleServiec;

  @Get('/role')
  async getUserList() {
    const list = await this.sysRoleService.getRoleList();
    return {
      code: '0',
      data: list,
      msg: 'ok',
    };
  }

  @Post('/role')
  async createRole(@Body(ALL) role: CreateRole) {
    const data = await this.sysRoleService.createRole(role);
    return {
      code: '0',
      data: data,
      msg: 'ok',
    };
  }

  @Put('/role')
  async updateRole(@Body(ALL) role: UpdateRoleDto) {
    const data = await this.sysRoleService.updateRole(role);
    return {
      code: 0,
      data: data,
      msg: 'OK',
    };
  }

  @Get('/getRoleById')
  async getRoleById(@Query() id: number) {
    const data = await this.sysRoleService.getRoleById(id);
    return {
      code: 0,
      data: data,
      msg: 'OK',
    };
  }
}
